package vip.idiy.anwei_android_iot.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import vip.idiy.anwei_android_iot.R;

/**
 * ClassName CustomDialog
 * describe: 消息框
 * Created: 勇
 * Email:118085890@qq.com
 * Version: 1.0
 * Create in 14:36 2023/4/21
 */
public class CustomDialog extends Dialog{
    Context mContext;

    private CustomDialogClickListener customDialogClickListener;


    private TextView title;


    private TextView message;


    public CustomDialog(@NonNull Context context, CustomDialogClickListener clickListener) {
        super(context, R.style.custom_dialog);
        this.mContext = context;
        this.customDialogClickListener = clickListener;
        initView();
    }



    /**
     * 对外提供设置提示标题的方法
     *
     * @param s 标题
     */
    public CustomDialog  setTitle(String s) {
        title.setText(s);
        return this;
    }

    /**
     * 对外提供设置提示信息的方法
     *
     * @param s 信息内容
     */
    public CustomDialog setMessage(String s) {
        message.setText(s);
        return this;
    }

    /**
     * 初始化View
     */
    public void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_custom_dialog, null);
        title = view.findViewById(R.id.custom_dialog_title);
        message = view.findViewById(R.id.custom_dialog_message);
         view.findViewById(R.id.custom_dialog_confirm_sure).setOnClickListener(v -> {
             CustomDialog.this.cancel();
             customDialogClickListener.doConfirm();
         });
         view.findViewById(R.id.custom_dialog_confirm_cancel).setOnClickListener(v -> {
             CustomDialog.this.cancel();
             customDialogClickListener.doCancel();
         });
        super.setContentView(view);
    }



    /**
     * Dialog Button接口
     */
    public interface CustomDialogClickListener {
        void doConfirm(); //确认
        void doCancel(); //取消
    }
}
